package com.company.ThreadPoolDemo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 作者  Administrator
 * 时间  2017/6/2 11:10
 * 文件  ThreadPoolsDemo
 * 描述
 */
public class CacheThread {
	public static void main(String[] args) {
		testCacheThreadPool();
	}
public static void testCacheThreadPool(){
	ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
	for (int i = 1; i <= 10; i++) {
		final int index = i;
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		cachedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				String threadName = Thread.currentThread().getName();
				System.out.println("线程：" + threadName + ",正在执行第" + index + "个任务");
				try {
					long time = index * 500;
					Thread.sleep(time);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
	}
 }
}


